package com.xjm.api.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xjm.entity.model.{{ class_name }}Model;
import com.xjm.entity.vo.PageVo;
import com.xjm.entity.vo.Result;
import com.xjm.service.{{ class_name }}Service;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/{{ table_name }}")
@RequiredArgsConstructor
public class {{ class_name }}Controller {

    private final {{ class_name }}Service {{ class_name.lower() }}Service;

    @GetMapping
    public Result<PageVo<{{ class_name }}Model>> list(
            @RequestParam(defaultValue = "1") Long page,
            @RequestParam(defaultValue = "5") Long size
    ) {
        return Result.success({{ class_name.lower() }}Service.page(new Page<>(page, size)));
    }

    @GetMapping("/{id}")
    public Result<{{ class_name }}Model> getById(@PathVariable Long id) {
        return Result.success({{ class_name.lower() }}Service.getById(id));
    }

    @PostMapping
    public Result<{{ class_name }}Model> add(@RequestBody {{ class_name }}Model {{ class_name.lower() }}Model) {
        {{ class_name.lower() }}Service.save({{ class_name.lower() }}Model);
        return Result.success();
    }

    @PutMapping
    public Result<{{ class_name }}Model> update(@RequestBody {{ class_name }}Model {{ class_name.lower() }}Model) {
        {{ class_name.lower() }}Model.setUpdatedTime(null);
        {{ class_name.lower() }}Service.updateById({{ class_name.lower() }}Model);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result<{{ class_name }}Model> delete(@PathVariable Long id) {
        {{ class_name.lower() }}Service.removeById(id);
        return Result.success();
    }
} 